package com.lab02.spring.firstpage.persistence;

import com.lab02.spring.firstpage.models.Player;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: bsceran
 * Date: 5/24/13
 * Time: 4:17 PM
 * To change this template use File | Settings | File Templates.
 */
public class PlayerDaoImpl extends SimpleJdbcDaoSupport implements PlayerDao {
    @Override
    public void add(Player player) {
        String sql = "INSERT INTO PLAYER (NAME, PHONE) VALUES (?, ?)";
        getSimpleJdbcTemplate().update(sql, player.getName(),player.getPhone());
    }

    @Override
    public void remove(String playerName) {
        String sql = "DELETE FROM PLAYER WHERE NAME = ?";
        getSimpleJdbcTemplate().update(sql, playerName);
    }

    @Override
    public List<Player> list() {
        String sql = "SELECT * FROM  PLAYER";
        return getSimpleJdbcTemplate().query(sql, ParameterizedBeanPropertyRowMapper.newInstance(Player.class));
    }
}
